package com.tj.controller;

import com.tj.pojo.SetMeal;
import com.tj.pojo.SetMealDetailed;
import com.tj.service.SetMealDetailedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/setMealDetailed")
public class SetMealDetailedController {

    @Autowired
    SetMealDetailedService setMealDetailedService;

    // ================================= 查询用户 =================================
    /*
     * -取得用户列表数据
     */
    @RequestMapping("/getSetMealDetailedList")
    public Map<String, Object> getSetMealDetailedList() throws Exception {
        List<SetMealDetailed> setMealDetailedList = setMealDetailedService.findSMDAllList();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("setMealDetailedList",setMealDetailedList);
        return map;
    }


    @RequestMapping("/getSetMealDetailedListBySdId")
    public Map<String, Object> getSetMealDetailedListBySdId(@RequestParam int sdId) throws Exception {
        List<SetMealDetailed> setMealDetailedList = setMealDetailedService.findSetMealDetailedListBySdId(sdId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("setMealDetailedList", setMealDetailedList);
        return map;
    }

    /*
     * -按ID查
     */
    @RequestMapping("/getSetMealDetailedBySmId")
    public Map<String, Object> getSetMealById(@RequestParam int smId) throws Exception {
        SetMealDetailed setMealDetailed = setMealDetailedService.findSetMealDetailedBySmId(smId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("setMealDetailed", setMealDetailed);
        return map;
    }

    // ================================= 增加用户 =================================
    @RequestMapping("/insertSetMealDetailed")
    public int insertSetMeal(@RequestBody SetMealDetailed setMealDetailed) {
        return setMealDetailedService.insertSetMealDetailed(setMealDetailed);
    }
    // ================================= 修改用户 =================================
    @RequestMapping("/updateSetMealDetailed")
    public int updateSetMeal(@RequestBody SetMealDetailed setMealDetailed) {
        return setMealDetailedService.updateSetMealDetailed(setMealDetailed);
    }
    // ================================= 删除用户 =================================
    /*
     * -执行用户删除的操作
     */
    @RequestMapping("/setDelete")
    public Map<String, Object> setDelete(HttpSession session, SetMealDetailed setMealDetailed) throws Exception {
        int num = setMealDetailedService.deleteSetMealDetailed(setMealDetailed);
        Map<String, Object> map = new HashMap<String, Object>();
        if (num > 0) {
            map.put("status", "1");
        } else {
            map.put("status", "0");
        }
        return map;
    }

}
